using Furion.DatabaseAccessor;
using Furion.IPCChannel;

namespace SB2.Core
{
    /// <summary>
    /// 表
    /// </summary>
    public class SysObjectAppService : ICoreService
    {
        private readonly SysObjectRepository repository;
        public SysObjectAppService(SysObjectRepository repository)
        {
            this.repository = repository;
        }

        /// <summary>
        /// 新建表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [UnitOfWork]
        public async Task<bool> NewTabeAsync(SysObjectNewTableDto dto)
        {
            return await repository.NewTabeAsync(dto);
        }
        /// <summary>
        /// 添加字段
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [UnitOfWork]
        public async Task<bool> NewFiledAsync(SysObjectNewFiledDto dto)
        {
            return await repository.NewFiledAsync(dto);
        }
        /// <summary>
        /// 加载新增页面参数
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        // [HttpGet]
        // public async Task<bool> Load()
        // {
        //     return await repository.NewFiledAsync(dto);
        // }

        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagedResponse> GetPageList(PagedRequest dto)
        {
            if (dto.Params == null) dto.Params = new List<SeachRequest>();
            dto.Params.Add(new SeachRequest { FieldName = "PId", Value = 0 });
            return await repository.GetPageListAsync<SysObjectDto>(dto);
        }

        /// <summary>
        /// 字段分页列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagedResponse> GetItemPageList(PagedRequest dto)
        {
            return await repository.GetPageListAsync<SysObjectFieldDto>(dto);
        }

    }
}